package userConsole.servlet;

import org.json.JSONException;
import org.json.JSONObject;
import userConsole.service.UserListService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * @author Godv
 * @version 1.0
 */
@WebServlet("/userListServlet")
public class UserListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserListService userListService = new UserListService();
        try {
            JSONObject jsonObject = userListService.userList();
            resp.setContentType("application/json;charset=utf-8");
            PrintWriter writer = resp.getWriter();
            writer.print(jsonObject);
            // 这里注意，在实际企业开发中，所有的接口返回的数据，最外部都是JSONObject，不会是直接返回一个jsonArray
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
